package com.sugar.follow.up.module.business.controller.admin.patient.qlxcajgjzxrslds;

import com.sugar.follow.up.framework.apilog.core.annotation.ApiAccessLog;
import com.sugar.follow.up.framework.common.pojo.CommonResult;
import com.sugar.follow.up.framework.common.pojo.PageParam;
import com.sugar.follow.up.framework.common.pojo.PageResult;
import com.sugar.follow.up.framework.common.util.object.BeanUtils;
import com.sugar.follow.up.framework.excel.core.util.ExcelUtils;
import com.sugar.follow.up.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.follow.up.module.business.controller.admin.patient.qlxcajgjzxrslds.vo.PatientQlxcajgjzxrsldsPageReqVO;
import com.sugar.follow.up.module.business.controller.admin.patient.qlxcajgjzxrslds.vo.PatientQlxcajgjzxrsldsRespVO;
import com.sugar.follow.up.module.business.controller.admin.patient.qlxcajgjzxrslds.vo.PatientQlxcajgjzxrsldsSaveReqVO;
import com.sugar.follow.up.module.business.dal.dataobject.patientqlxcajgjzxrslds.PatientQlxcajgjzxrsldsDO;
import com.sugar.follow.up.module.business.service.patientqlxcajgjzxrslds.PatientQlxcajgjzxrsldsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static com.sugar.follow.up.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.sugar.follow.up.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 前列腺Ca激光局灶消融术/冷冻术")
@RestController
@RequestMapping("/business/patient-qlxcajgjzxrslds")
@Validated
public class PatientQlxcajgjzxrsldsController {

    @Resource
    private PatientQlxcajgjzxrsldsService patientQlxcajgjzxrsldsService;

    @PostMapping("/create")
    @Operation(summary = "创建前列腺Ca激光局灶消融术/冷冻术")
    //@PreAuthorize("@ss.hasPermission('business:patient-qlxcajgjzxrslds:create')")
    public CommonResult<Long> createPatientQlxcajgjzxrslds(@Valid @RequestBody PatientQlxcajgjzxrsldsSaveReqVO createReqVO) {
        return success(patientQlxcajgjzxrsldsService.createPatientQlxcajgjzxrslds(createReqVO, SecurityFrameworkUtils.getLoginUserId()));
    }

    @PutMapping("/update")
    @Operation(summary = "更新前列腺Ca激光局灶消融术/冷冻术")
    //@PreAuthorize("@ss.hasPermission('business:patient-qlxcajgjzxrslds:update')")
    public CommonResult<Boolean> updatePatientQlxcajgjzxrslds(@Valid @RequestBody PatientQlxcajgjzxrsldsSaveReqVO updateReqVO) {
        patientQlxcajgjzxrsldsService.updatePatientQlxcajgjzxrslds(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除前列腺Ca激光局灶消融术/冷冻术")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('business:patient-qlxcajgjzxrslds:delete')")
    public CommonResult<Boolean> deletePatientQlxcajgjzxrslds(@RequestParam("id") Long id) {
        patientQlxcajgjzxrsldsService.deletePatientQlxcajgjzxrslds(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除前列腺Ca激光局灶消融术/冷冻术")
    //@PreAuthorize("@ss.hasPermission('business:patient-qlxcajgjzxrslds:delete')")
    public CommonResult<Boolean> deletePatientQlxcajgjzxrsldsList(@RequestParam("ids") List<Long> ids) {
        patientQlxcajgjzxrsldsService.deletePatientQlxcajgjzxrsldsListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得前列腺Ca激光局灶消融术/冷冻术")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('business:patient-qlxcajgjzxrslds:query')")
    public CommonResult<PatientQlxcajgjzxrsldsRespVO> getPatientQlxcajgjzxrslds(@RequestParam("id") Long id) {
        PatientQlxcajgjzxrsldsDO patientQlxcajgjzxrslds = patientQlxcajgjzxrsldsService.getPatientQlxcajgjzxrslds(id);
        return success(BeanUtils.toBean(patientQlxcajgjzxrslds, PatientQlxcajgjzxrsldsRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得前列腺Ca激光局灶消融术/冷冻术分页")
    //@PreAuthorize("@ss.hasPermission('business:patient-qlxcajgjzxrslds:query')")
    public CommonResult<PageResult<PatientQlxcajgjzxrsldsRespVO>> getPatientQlxcajgjzxrsldsPage(@Valid PatientQlxcajgjzxrsldsPageReqVO pageReqVO) {
        PageResult<PatientQlxcajgjzxrsldsDO> pageResult = patientQlxcajgjzxrsldsService.getPatientQlxcajgjzxrsldsPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PatientQlxcajgjzxrsldsRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出前列腺Ca激光局灶消融术/冷冻术 Excel")
    //@PreAuthorize("@ss.hasPermission('business:patient-qlxcajgjzxrslds:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportPatientQlxcajgjzxrsldsExcel(@Valid PatientQlxcajgjzxrsldsPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PatientQlxcajgjzxrsldsDO> list = patientQlxcajgjzxrsldsService.getPatientQlxcajgjzxrsldsPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "前列腺Ca激光局灶消融术/冷冻术.xls", "数据", PatientQlxcajgjzxrsldsRespVO.class,
                        BeanUtils.toBean(list, PatientQlxcajgjzxrsldsRespVO.class));
    }

}